package LearnDataStructure.c_树结构;

/**
 * @version: 1.0
 * @Author: wuqiu
 * @date: 2023-07-07 22:00
 * @description: LeetcodeLearnAlgorithm -> LearnDataStructure.c_树结构
 */
public class BSTNode<K, V> {
    public K key;
    public V value;
    public BSTNode<K, V> left;
    public BSTNode<K, V> right;
    public BSTNode<K, V> parent;
    public boolean isLeftChild;     //左孩子标志
    public int height;              //以此节点为根的子树的高度；注意这个不能直接返回当作
    public int num;                 //二叉树编号
    public boolean isRed = true;

    public BSTNode(K key, V value, BSTNode<K, V> left, BSTNode<K, V> right, BSTNode<K, V> parent) {
        this.key = key;
        this.value = value;
        this.left = left;
        this.right = right;
        this.parent = parent;
    }

    public BSTNode() {
    }

    public boolean isLeft() {
        return isLeftChild;
    }

    public boolean isRight() {
        return !isLeftChild;
    }

    @Override
    public String toString() {
        return (isRed ? "红色" : "黑色") +  " [" + key + "]<-" + (parent == null ? "" : parent.key);
    }
}
